@extends("layouts.common")
@section("content")

    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header"><i class="fa fa-table"></i>我的客户</h3>
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i><a href="/welcome">Home</a></li>
                <li><i class="fa fa-table"></i>我的客户</li>
            </ol>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-indent red"></i><strong>搜索</strong></h2>
                </div>
                <form action="" method="get" class="form-inline">
                    <div class="panel-body">

                        <div class="form-group">
                            <label class="sr-only" for="if-password">姓名</label>
                            <input type="text" id="if-password" name="name" class="form-control" placeholder="姓名">
                        </div>
                        <div class="form-group">
                            <label class="sr-only" for="if-email">Email</label>
                            <input type="text" id="if-email" name="email" class="form-control" placeholder="邮箱">
                        </div>
                        <div class="form-group">
                            <label class="sr-only" for="if-email">Email</label>
                            <input type="text" id="if-email" name="phone" class="form-control" placeholder="手机">
                        </div>
                    </div>
                    <div class="panel-footer">
                        <button type="submit" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> 搜索</button>
                        <button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> 重置</button>
                    </div>
                </form>
            </div>

        </div>
    </div>

    <div class="row">

        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-table red"></i><span class="break"></span><strong>我的客户</strong></h2>
                </div>

                <div class="panel-body">
                    <table class="table table-condensed">
                        <thead>
                        <tr>
                            <th>姓名</th>
                            <th>邮箱</th>
                            <th>手机</th>
                            <th>交易账号</th>
                            <th>国家</th>
                            <th>城市</th>
                            <th>生日</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($list as $val)
                        <tr>
                            <td>{{$val->firstname.$val->lastname}}</td>
                            <td>{{$val->email}}</td>
                            <td>{{$val->phone}}</td>
                            <td>{{$val->tranid}}</td>
                            <td>{{$val->country}}</td>
                            <td>{{$val->city}}</td>
                            <td>{{$val->birth}}</td>
                            <td>
                                @if($val->act=='0')
                                    <a class="btn btn-primary btn-release"  data-toggle="modal" data-target="#releaseModal" data-val="{{$val->id}}"> 升级为代理</a>
                                @endif
                                    @if($val->tranid!='')
                                        <a href="/customer/list/{{$val->tranid}}" class="btn btn-primary btn-release"> 交易记录</a>
                                    @endif


                            </td>
                        </tr>
                            @endforeach

                        </tbody>
                    </table>
                    @include("layouts.page",['paginator'=>$list])
                </div>



                <div class="modal fade" id="releaseModal" tabindex="-1" role="dialog" aria-labelledby="releaseModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="releaseModalLabel">提示</h4>
                            </div>
                            <div class="modal-body">
                                你确定要升级为代理？
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                                <a  class="btn btn-primary active btn-sm" data-val="" role="button">确定</a>
                            </div>
                        </div>
                    </div>
                </div>

            </div>


            <div class="row">

                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <h2><i class="fa fa-indent red"></i><strong>邀请链接</strong></h2>
                        </div>
                        <div class="panel-body">
                            <div class="form-group" style="display: block">
                                <label class="col-md-3 control-label" for="text-input">邀请链接</label>
                                <div class="col-md-9">
                                    <p class="form-control" >http://{{$_SERVER["HTTP_HOST"]}}/home/{{Auth::user()->code}}</p>

                                </div>
                            </div>
                            <div class="form-group" style="display: block">
                                <label class="col-md-3 control-label" for="text-input">邀请二维码</label>
                                <div class="col-md-9">
                                    {{--<p class="form-control" > <img src="{!!QrCode::format('png')->generate('Embed me into an e-mail!')!!}"></p>--}}
                                    {!! QrCode::size(200)->generate("http://".$_SERVER["HTTP_HOST"]."/home/".Auth::user()->code) !!}
                                    {{--<img src="{{$code}}">--}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div><!--/col-->
    </div>
    <script src="https://cdn.bootcss.com/jquery/2.2.1/jquery.min.js"></script>
    <style>
        td,th{
            text-align: center;
        }
    </style>

    <script>
        $(function(){
            $(".btn-release").click(function(){
                $("#releaseModal").find('.modal-footer .btn-primary').attr('href', "/customer/upgrade/" + $(this).data("val"));
            });

            var search = location.search.substring(1);
            if (search) {
                try {
                    var query = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');

                    $.each(query, function(k, v) {
                        $('[name=' + k + ']').val(v);
                    });
                } catch (e) {
                    console.log(e);
                }

            }
        });

    </script>
@endsection